/**
 * Main application routes
 */
'use strict';

var errors = require('./components/errors');
var path = require('path');
var config = require('./config/environment');

module.exports = function (app) {

    app.all('*', function (req, res, next) {
        res.header("Access-Control-Allow-Origin", "*");
        // res.header("Access-Control-Allow-Credentials", "true");
        res.header("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,X-XSRF-TOKEN");
        res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS,PATCH");
        next();
    });

    // 表配置
    // Model
    // app.use('/api/v1/things', require('./api/thing'));
    app.use('/api/v1/users', require('./api/user'));
    app.use('/api/v1/studentlists', require('./api/studentlist'));
    app.use('/api/v1/teacherlists', require('./api/teacherlist'));
    app.use('/api/v1/titlelists', require('./api/titlelist'));
    app.use('/api/v1/tasklists', require('./api/tasklist'));
    app.use('/api/v1/notices', require('./api/notices'));

    // All undefined asset or api routes should return a 404
    app.route('/:url(api|auth|components|app|bower_components|assets)/*')
        .get(errors[404]);

    // All other routes should redirect to the index.html
    app.route('/*')
        .get(function (req, res) {
            res.sendFile(path.resolve(config.root + '/views/index.html'));
        });
};